import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image,Video } from '@tarojs/components'
import './projectdetails.css'
import { AtGrid, AtTag } from "taro-ui"
import reactMixin from 'react-mixin';
import myJs from './projectdetailsJs.js'
import app from '../../../../main.js'

export default class ProjectDetails extends Component {

    config = {
        navigationBarTitleText: '项目详情'
    }

    constructor() {
        super(...arguments);
        this.state = {
            project: {},
            publish_amount: 0
        };
    }

    init() { 
        this.getProject();
        this.getPublishAmount();
        app.showShareMenu();
    }

    getProject() {
        let me = this;
        app.get("web/project/get", {id: this.$router.params.id}, function(res) {
            let project = res.data.result;
            project.start_time = project.start_time.substr(0,10);
            project.end_time = project.end_time.substr(0,10);
            me.setState({
                project: project
            });
        });
    }

    getPublishAmount() {
        let me = this;
        app.get("web/project/publish_amount", {project_id: this.$router.params.id}, function(res) {
            me.setState({
                publish_amount: res.data.result.publish_amount
            });
        });
    }

    go = (item, index) => {
        switch (index) {
            case 0: 
                this.navigateTo('../../../doctorpages/createCase/createCase?type=病例&project_id='+this.$router.params.id);
                break;
            case 1: 
                if (this.state.publish_amount > 0)
                    app.navigateTo('../xiangmubingli/xiangmubingli?projectId='+this.state.project.id+'&docid='+this.$router.params.docid);
                else
                    app.navigateTo('../projectnotfound/projectnotfound?title=项目病历&content=您还没为该项目发布过病历呢');    
                break;
            case 2: 
                if (this.state.publish_amount > 0)
                    app.navigateTo('../xiangmujindu/xiangmujindu?projectId='+this.state.project.id);
                else
                    app.navigateTo('../projectnotfound/projectnotfound?title=项目进度&content=您还没为该项目发布过病历呢');    
                break;
            case 3: 
                if (this.state.publish_amount > 0)
                    app.navigateTo('../xiangmufenxi/xiangmufenxi');
                else 
                    app.navigateTo('../projectnotfound/projectnotfound?title=数据分析&content=您还没为该项目发布过病历呢');
                break;
        }
    }

    render() {
        return (
            <View className='project-details'>
                <AtGrid columnNum={3} onClick={this.go} className='header' hasBorder={false} data={
                    [
                        {
                            image: app.imageUri + 'img/tianjiabingli.png',
                            value: '添加病历'
                        },
                        {
                            image: app.imageUri + 'img/xiangmubingli.png',
                            value: '项目病历'
                        },
                        {
                            image: app.imageUri + 'img/xiangmujindu.png',
                            value: '项目进度'
                        },
                        // {
                        //     image: app.imageUri + 'img/shujufenxi.png',
                        //     value: '数据分析'
                        // }
                    ]
                } />
                <View className='at-article'>
                    <View className='at-article__h1'>
                    {this.state.project.name}
                    </View>
                    <View className='at-article__p'>
                        <View className='gongsi'>
                            <View className='songsimingcheng'>{this.state.project.leader}</View>
                            <View className='shijian'>{this.state.project.start_time} 至 {this.state.project.end_time}</View>
                        </View>
                    </View>
                    <View className='v_image'><Image className='main_image' src={app.getPath(this.state.project.image)}></Image></View>
                    <View className='at-article__p'>
                        {this.state.project.desc}
                    </View>
                </View>
                <View>
                    <View className='fenxiang'>
                        <View className='fenxiang1'>分享给好友</View>
                    </View>
                    <View className='box'>
                        <View class='share'> <Image className='fenxianghaoyou' src={app.getPath('img/icon_weixin.png')}></Image><View>微信好友</View></View>
                        <View class='share1'><Image className='fenxianghaoyou1' src={app.getPath('img/icon_weixin.png')}></Image><View>微信朋友圈</View></View>
                        <View class='share2'><Image className='fenxianghaoyou2' src={app.getPath('img/icon_weibo.png')}></Image><View>新浪微博</View></View>
                    </View>
                </View>
            </View>

        )
    }
}
reactMixin.onClass(ProjectDetails, myJs);


